home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / EXPFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  31.9 KB  |  1,106 lines

  1. {********************************************}
  2. {  TeeChart Wizard                           }
  3. {  Copyright (c) 1995-1998 by David Berneda  }
  4. {  All Rights Reserved                       }
  5. {********************************************}
  6. {$I Teedefs.inc}
  7. unit ExpForm;
  8.  
  9. interface
  10.  
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   ExtCtrls, StdCtrls, Buttons, ToolIntf, ComCtrls, TeEngine, Chart, DbChart,
  14.   DB, DBTables, TeeGally,  DBCtrls, TeeProcs, TeeConst, DBCombo, BDE,
  15.   {$IFDEF D3}
  16.   dsnConst,ActiveX,
  17.   {$ELSE}
  18.   LibConst,
  19.   {$ENDIF}
  20.   dsnDBcst, FileCtrl;
  21.  
  22. type
  23.   TSources = (stLocal, stAlias);
  24.  
  25.   TTeeDlgWizard = class(TForm)
  26.     CancelBtn: TButton;
  27.     PrevButton: TButton;
  28.     NextButton: TButton;
  29.     PageControl: TPageControl;
  30.     TabStyle: TTabSheet;
  31.     Label1: TLabel;
  32.     TableName: TTabSheet;
  33.     Label3: TLabel;
  34.     Buttons: TTabSheet;
  35.     Label2: TLabel;
  36.     TabSheet1: TTabSheet;
  37.     Label4: TLabel;
  38.     TabSheet2: TTabSheet;
  39.     Table1: TTable;
  40.     PanelGallery: TPanel;
  41.     Panel1: TPanel;
  42.     LBAvailFields: TListBox;
  43.     LBSelectedFields: TListBox;
  44.     Button3: TButton;
  45.     Button2: TButton;
  46.     Button4: TButton;
  47.     Button5: TButton;
  48.     Panel2: TPanel;
  49.     Label6: TLabel;
  50.     cbLabelsFields: TComboBox;
  51.     PageControl1: TPageControl;
  52.     TabPreviewChart: TTabSheet;
  53.     PreviewChart: TDBChart;
  54.     Bevel3: TBevel;
  55.     rbChart2D: TRadioButton;
  56.     rbChart3D: TRadioButton;
  57.     Panel3: TPanel;
  58.     rbDatabase: TRadioButton;
  59.     rbNonDatabase: TRadioButton;
  60.     Label7: TLabel;
  61.     Label8: TLabel;
  62.     Panel7: TPanel;
  63.     CB3DOption: TCheckBox;
  64.     CBShowLegendOption: TCheckBox;
  65.     CBShowMarksOption: TCheckBox;
  66.     Button1: TButton;
  67.     Panel8: TPanel;
  68.     Label27: TLabel;
  69.     DirPath: TLabel;
  70.     FileEdit: TEdit;
  71.     PathText: TLabel;
  72.     AliasFileList: TAliasFileListBox;
  73.     AliasPathList: TAliasListBox;
  74.     FilterList: TFilterComboBox;
  75.     Label26: TLabel;
  76.     Label25: TLabel;
  77.     AliasDriveList: TAliasDrive;
  78.     Panel4: TPanel;
  79.     Image2: TImage;
  80.     LabelURL: TLabel;
  81.     procedure FormCreate(Sender: TObject);
  82.     procedure CancelClick(Sender: TObject);
  83.     procedure PrevClick(Sender: TObject);
  84.     procedure NextClick(Sender: TObject);
  85.     procedure Button5Click(Sender: TObject);
  86.     procedure Button4Click(Sender: TObject);
  87.     procedure Button2Click(Sender: TObject);
  88.     procedure Button3Click(Sender: TObject);
  89.     procedure LBAvailFieldsClick(Sender: TObject);
  90.     procedure LBSelectedFieldsClick(Sender: TObject);
  91.     procedure rbChart3DClick(Sender: TObject);
  92.     procedure rbChart2DClick(Sender: TObject);
  93.     procedure Image1Click(Sender: TObject);
  94.     procedure CB3DOptionClick(Sender: TObject);
  95.     procedure CBShowLegendOptionClick(Sender: TObject);
  96.     procedure CBShowMarksOptionClick(Sender: TObject);
  97.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  98.       Shift: TShiftState);
  99.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  100.     procedure Button1Click(Sender: TObject);
  101.     procedure FileEditChange(Sender: TObject);
  102.     procedure FileEditKeyPress(Sender: TObject; var Key: Char);
  103.     procedure AliasFileListClick(Sender: TObject);
  104.     procedure AliasFileListDblClick(Sender: TObject);
  105.     procedure AliasPathListChange(Sender: TObject);
  106.     procedure FilterListChange(Sender: TObject);
  107.     procedure AliasDriveListChange(Sender: TObject);
  108.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  109.     procedure LabelURLClick(Sender: TObject);
  110.   private
  111.     { Private declarations }
  112.     tmpGallery:TTeeGallery;
  113.     SourceBuffer: PChar;
  114.     procedure RefreshButtons;
  115.     procedure FmtWrite(Stream: TStream; Const Fmt: String; const Args: array of const);
  116.     function DoFormCreation(const FormIdent: string): TForm;
  117.   public
  118.     { Public declarations }
  119.     { Table Selection }
  120.     BackupDir,
  121.     WizardAliasName,
  122.     WizardPath:String;
  123.     ForceUpdate:Boolean;
  124.     WizardTableName:String;
  125.     WizardDriveIndex:Integer;
  126.     WizardSource:TSources;
  127.     { General }
  128.     Procedure CreateSeries( AOwner:TComponent;
  129.                             AChart:TCustomChart;
  130.                             ATable:TTable;
  131.                             ShowData:Boolean );
  132.     {$IFDEF C3}
  133.     function CreateHeader(const UnitIdent, FormIdent: string): TMemoryStream;
  134.     function CreateCppSource(const FormIdent: string): TMemoryStream;
  135.     {$ENDIF}
  136.     function CreateSource(const UnitIdent, FormIdent: string): TMemoryStream;
  137.     function CreateForm(const FormIdent: string): TMemoryStream;
  138.     procedure SetChartOptions;
  139.     procedure GallerySelectedChart(Sender: TObject);
  140.     { TableSelection }
  141.     function AliasPath(const AliasName: string): string;
  142.     procedure SetFileEditText(const Value: string);
  143.     procedure SetFilter(const AFilter: string);
  144.     procedure InitFilter;
  145.   end;
  146.  
  147. procedure TeeChartWizard(ToolServices: TIToolServices);
  148.  
  149. implementation
  150.  
  151. uses Proxies, VirtIntf, IStreams, TeeLisB, TeeAbout, Series;
  152.  
  153. {$R *.DFM}
  154.  
  155. const
  156.   { page numbers }
  157.   pgStyle       = 0;  { Database vs. Non-Database }
  158.   pgTable       = 1;  { Table name }
  159.   pgFields      = 2;  { Fields }
  160.   pgGallery     = 3;  { Chart Type }
  161.   pgPreviewChart= 4;  { Preview }
  162.  
  163.   TeeMsg_WizardChart1   = 'Chart1'; {  <-- dont translate }
  164.   TeeMsg_WizardDBChart1 = 'DBChart1'; {  <-- dont translate }
  165.   TeeMsg_WizardTable1   = 'Table1'; {  <-- dont translate }
  166.  
  167.   SourceBufferSize = 1024;
  168.  
  169. { TeeChart Wizard }
  170.  
  171. Var LocalFilter:String='';
  172.     RemoteFilter:String='';
  173.  
  174. procedure TTeeDlgWizard.InitFilter;
  175. begin
  176.   SetFilter(LocalFilter);
  177.   with FilterList do
  178.   begin
  179.     SetFileEditText(Mask);
  180.     AliasFileList.Mask := Mask;
  181.   end;
  182. end;
  183.  
  184. procedure TTeeDlgWizard.FileEditChange(Sender: TObject);
  185. var
  186.   Index: Integer;
  187. begin
  188.   Index := AliasFileList.Items.IndexOf(FileEdit.Text);
  189.   if Index<>LB_ERR then
  190.   begin
  191.     NextButton.Enabled := True;
  192.     AliasFileList.ItemIndex := Index;
  193.     WizardTableName := FileEdit.Text;
  194.   end
  195.   else NextButton.Enabled := False;
  196. end;
  197.  
  198. procedure TTeeDlgWizard.FileEditKeyPress(Sender: TObject; var Key: Char);
  199. var TempStr : String;
  200.     Alias   : String;
  201.     Dir     : String;
  202.     FileName: String;
  203.     Index   : Integer;
  204. begin
  205.   if Key = Chr(VK_RETURN) then
  206.   begin
  207.     Index := AliasFileList.Items.IndexOf(FileEdit.Text);
  208.     if Index <> LB_ERR then
  209.     begin
  210.       NextButton.Enabled := True;
  211.       AliasFileList.ItemIndex := Index;
  212.     end
  213.     else begin
  214.       TempStr := FileEdit.Text;
  215.       ForceUpdate:= False;
  216.       try
  217.         ProcessAlias(TempStr, Alias, Dir, FileName);
  218.         if AliasDriveList.SetAlias(Alias) then
  219.            AliasPathList.Directory := TempStr
  220.         else
  221.            TempStr := FileName;
  222.         if TempStr <> '' then AliasFileList.ApplyFilePath(TempStr)
  223.         else AliasFileList.Update;
  224.       finally
  225.         ForceUpdate := True;
  226.       end;
  227.       if FileName <> '' then
  228.       begin
  229.         SetFileEditText(FileName);
  230.         NextButton.Enabled := True;
  231.       end else
  232.         SetFileEditText(AliasFileList.Mask);
  233.     end;
  234.     Key := Chr(0);
  235.   end;
  236. end;
  237.  
  238. procedure TTeeDlgWizard.AliasFileListClick(Sender: TObject);
  239. begin
  240.   with AliasFileList do
  241.     SetFileEditText(Items[ItemIndex]);
  242. end;
  243.  
  244. procedure TTeeDlgWizard.AliasFileListDblClick(Sender: TObject);
  245. begin
  246.   AliasFileListClick(Sender);
  247.   NextClick(Sender);
  248. end;
  249.  
  250. procedure TTeeDlgWizard.AliasPathListChange(Sender: TObject);
  251. var ItemStr: TFileName;
  252. begin
  253.   with AliasPathList do
  254.   begin
  255.     if ShowAlias then
  256.     begin
  257.       DirPath.Enabled := False;
  258.       WizardPath := WizardAliasName;
  259.       with AliasFileList do
  260.       begin
  261.         ShowAlias := True;
  262.         AliasName := WizardAliasName;
  263.         System := FilterList.ItemIndex = 1;
  264.         if ForceUpdate then Update;
  265.       end;
  266.       ItemStr := EmptyStr
  267.     end else
  268.     begin
  269.       WizardPath := Directory;
  270.       DirPath.Enabled := True;
  271. {$IFDEF D3}
  272.       ItemStr := AnsiLowerCaseFileName(GetItemPath(ItemIndex));
  273. {$ELSE}
  274.       ItemStr := LowerCase(GetItemPath(ItemIndex));
  275. {$ENDIF}
  276.       AliasFileList.ShowAlias := False;
  277. {$IFDEF D3}
  278.       if AnsiCompareFileName(AliasFileList.Directory,Directory) = 0 then
  279. {$ELSE}
  280.       if UpperCase(AliasFileList.Directory) = UpperCase(Directory) then
  281. {$ENDIF}
  282.         AliasFileList.Update
  283.       else AliasFileList.ApplyFilePath(Directory);
  284.       if Canvas.TextWidth(ItemStr) > PathText.Width then
  285.         ItemStr := MinimizeName(ItemStr, Canvas, PathText.Width);
  286.     end;
  287.     PathText.Caption := ItemStr;
  288.   end;
  289. end;
  290.  
  291. procedure TTeeDlgWizard.SetFilter(const AFilter: string);
  292. begin
  293.   with FilterList do
  294.   begin
  295.     Filter := AFilter;
  296.     ItemIndex := 2;
  297.   end;
  298. end;
  299.  
  300. procedure TTeeDlgWizard.SetFileEditText(const Value: string);
  301. begin
  302.   with FileEdit do
  303.   begin
  304.     Text := Value;
  305.     SelectAll;
  306.   end;
  307. end;
  308.  
  309. procedure TTeeDlgWizard.FilterListChange(Sender: TObject);
  310. begin
  311.   with AliasFileList do
  312.   begin
  313.     Mask := FilterList.Mask;
  314.     if (Items.IndexOf(FileEdit.Text) = LB_ERR) and
  315.        (WizardTableName = '') then
  316.         SetFileEditText(Mask);
  317.     if ShowAlias then
  318.     begin
  319.       AliasName := WizardAliasName;
  320.       System := FilterList.ItemIndex = 1;
  321.       if ForceUpdate then Update;
  322.     end;
  323.   end;
  324. end;
  325.  
  326. procedure TTeeDlgWizard.AliasDriveListChange(Sender: TObject);
  327. var
  328.   Index: Integer;
  329.   NewPath: string;
  330.  
  331.   procedure CheckAliasDrive(CurDrive: Char);
  332.   begin
  333.     with AliasPathList do
  334.     begin
  335.       ShowAlias := False;
  336.       if UpCase(Drive) = UpCase(CurDrive) then Update
  337.       else Drive := CurDrive;
  338.       SetFilter(LocalFilter);
  339.     end;
  340.   end;
  341.  
  342. begin
  343.   with AliasDriveList do
  344.   begin
  345.     Index := ItemIndex;
  346.     WizardDriveIndex := Index;
  347.     if Index > AliasList.Count - 1 then
  348.     begin
  349.       WizardSource := stLocal;
  350.       if AliasPathList.ShowAlias then CheckAliasDrive(Drive)
  351.                                  else AliasPathList.Drive := Drive;
  352.       InitFilter;
  353.     end else
  354.     begin
  355.       with AliasPathList do
  356.       begin
  357.         WizardAliasName := AliasDriveList.Items[Index];
  358.         NewPath := AliasPath(WizardAliasName);
  359.         if NewPath = EmptyStr then
  360.         begin
  361.           WizardSource := stAlias;
  362.           AliasName := AliasDriveList.Items[Index];
  363.           AliasBitmap := TBitmap(AliasDriveList.Items.Objects[Index]);
  364.           ShowAlias := True;
  365.           SetFilter(RemoteFilter);
  366.           Update;
  367.         end else
  368.         begin
  369.           WizardSource := stLocal;
  370.           ShowAlias := False;
  371.           {$IFDEF D3}
  372.           if AnsiCompareText(Directory, NewPath) = 0 then
  373.           {$ELSE}
  374.           if CompareText(Directory, NewPath) = 0 then
  375.           {$ENDIF}
  376.                 Update
  377.           else
  378.                 Directory := NewPath;
  379.           InitFilter;
  380.         end;
  381.       end;
  382.     end;
  383.   end;
  384. end;
  385.  
  386. function TTeeDlgWizard.AliasPath(const AliasName: string): string;
  387. var
  388.   Desc: DBDesc;
  389.   SAliasName: array [0..DBIMAXNAMELEN - 1] of char;
  390.   TempDatabase: TDatabase;
  391. begin
  392.   with TTable.Create(nil) do
  393.   try
  394.     TempDatabase := Session.OpenDatabase(AliasName);
  395.     try
  396.       StrPLCopy(SAliasName, AliasName, SizeOf(SAliasName) - 1);
  397.       AnsiToOem(SAliasName, SAliasName);
  398.       Result := '';
  399.       if DbiGetDatabaseDesc(SAliasName, @Desc) = 0 then
  400.         if StrPas(Desc.szDbType) = 'STANDARD' then
  401.         begin
  402.           OemToAnsi(Desc.szPhyName, Desc.szPhyName);
  403.           Result := StrPas(Desc.szPhyName);
  404.         end;
  405.     finally
  406.       Session.CloseDatabase(TempDatabase);
  407.     end;
  408.   finally
  409.     Free;
  410.   end;
  411. end;
  412.  
  413. { Paint the sample pane based on the currently selected options }
  414. procedure TTeeDlgWizard.FormCreate(Sender: TObject);
  415. Var AliasList:TStringList;
  416. begin
  417.   tmpGallery:=nil;
  418.   GetDir(0,BackupDir);
  419.   PageControl.ActivePage:=TabStyle;
  420.   {$IFDEF D3}
  421.   LocalFilter := SLocalFilter;
  422.   RemoteFilter := SRemoteFilter;
  423.   LabelURL.Cursor := crHandPoint;
  424.   {$ELSE}
  425.   LocalFilter := LoadStr(SLocalFilter);
  426.   RemoteFilter := LoadStr(SRemoteFilter);
  427.   {$ENDIF}
  428.   WizardTableName:='';
  429.   WizardAliasName:='';
  430.   WizardPath:='';
  431.   ForceUpdate:=True;
  432.   AliasList := TStringList.Create;
  433.   AliasList.Sorted := True;
  434.   Session.GetDatabaseNames(AliasList);
  435.   AliasDriveList.AddAliases(AliasList);
  436.   AliasList.Free;
  437.   AliasPathListChange(Self);
  438.   RefreshButtons;
  439. end;
  440.  
  441. procedure TTeeDlgWizard.CancelClick(Sender: TObject);
  442. begin
  443.   Close;
  444. end;
  445.  
  446. procedure TTeeDlgWizard.PrevClick(Sender: TObject);
  447. begin
  448.   With PageControl do
  449.   case ActivePage.PageIndex of
  450.     pgStyle  : Exit;
  451.     pgTable  : ActivePage := Pages[pgStyle];
  452.     pgFields : ActivePage := Pages[pgTable];
  453.     pgGallery: if rbDatabase.Checked then ActivePage := Pages[pgFields]
  454.                                      else ActivePage := Pages[pgStyle];
  455.     pgPreviewChart: ActivePage := Pages[pgGallery];
  456.   end;
  457.   RefreshButtons;
  458. end;
  459.  
  460. procedure TTeeDlgWizard.GallerySelectedChart(Sender: TObject);
  461. begin
  462.   PageControl.ActivePage := PageControl.Pages[pgPreviewChart];
  463.   if rbDatabase.Checked then
  464.      CreateSeries(Self,PreviewChart,Self.Table1,True)
  465.   else
  466.      CreateSeries(Self,PreviewChart,nil,True);
  467.   CB3DOption.Checked:=PreviewChart.View3D;
  468.   CBShowLegendOption.Checked:=PreviewChart.Legend.Visible;
  469.   CBShowMarksOption.Visible:=PreviewChart.SeriesCount>0;
  470.   if PreviewChart.SeriesCount>0 then
  471.      CBShowMarksOption.Checked:=PreviewChart[0].Marks.Visible;
  472.   PageControl1.ActivePage:=TabPreviewChart;
  473.   RefreshButtons;
  474. end;
  475.  
  476. procedure TTeeDlgWizard.NextClick(Sender: TObject);
  477.  
  478.   Procedure ActiveGallery;
  479.   begin
  480.     PageControl.ActivePage := PageControl.Pages[pgGallery];
  481.     rbChart3D.Checked:=PreviewChart.View3D;
  482.     if not Assigned(tmpGallery) then
  483.     begin
  484.       tmpGallery:=TTeeGallery.Create(Self);
  485.       With tmpGallery do
  486.       begin
  487.         BorderStyle:=bsNone;
  488.         Left:=0;
  489.         Top:=0;
  490.         Align:=alClient;
  491.         Parent:=PanelGallery;
  492.         HideButtons;
  493.         HideFunctions;
  494.         GalleryPanel.OnSelectedChart:=GallerySelectedChart;
  495.         GalleryPanel.SetRowCols(2,4);
  496.         CreateGalleryList([ TLineSeries,
  497.                             TBarSeries,
  498.                             THorizBarSeries,
  499.                             TAreaSeries,
  500.                             TPointSeries,
  501.                             TPieSeries,
  502.                             TFastLineSeries
  503.                          ]);
  504.         Show;
  505.       end;
  506.     end;
  507.   end;
  508.  
  509. var t               : Integer;
  510.     tmpDatabaseName : String;
  511. begin
  512.   case PageControl.ActivePage.PageIndex of
  513.     pgStyle:  if rbDatabase.Checked then
  514.               begin
  515.                 PageControl.ActivePage := PageControl.Pages[pgTable];
  516.                 { init table selection }
  517.                 InitFilter;
  518.               end
  519.               else ActiveGallery;
  520.     pgTable:  begin
  521.                 PageControl.ActivePage := PageControl.Pages[pgFields];
  522.                 if WizardAliasName<>'' then tmpDatabaseName:=WizardAliasName
  523.                                        else tmpDatabaseName:=WizardPath;
  524.                 if (Table1.DatabaseName<>tmpDatabaseName) or
  525.                    (Table1.TableName<>WizardTableName) then
  526.                 begin
  527.                   Table1.Close;
  528.                   Table1.DatabaseName:=tmpDatabaseName;
  529.                   Table1.TableName:=WizardTableName;
  530.                   Table1.FieldDefs.Update;
  531.                   LBAvailFields.Clear;
  532.                   LBSelectedFields.Clear;
  533.                   cbLabelsFields.Clear;
  534.                   for t:=0 to Table1.FieldDefs.Count-1 do
  535.                   begin
  536.                     Case Table1.FieldDefs[t].DataType of
  537.                       ftSmallint,
  538.                       ftInteger,
  539.                       ftWord,
  540.                       ftFloat,
  541.                       ftCurrency,
  542.                       ftBCD,
  543.                       ftDate,
  544.                       ftTime,
  545.                       ftDateTime: begin
  546.                                     LBAvailFields.Items.Add(Table1.FieldDefs[t].Name);
  547.                                     cbLabelsFields.Items.Add(Table1.FieldDefs[t].Name);
  548.                                   end;
  549.                       ftString: cbLabelsFields.Items.Add(Table1.FieldDefs[t].Name);
  550.                     end;
  551.                   end;
  552.                   for t:=0 to PreviewChart.SeriesCount-1 do
  553.                       PreviewChart[t].DataSource:=nil;
  554.                   Table1.Open;
  555.                 end;
  556.               end;
  557.     pgFields: if LBSelectedFields.Items.Count > 0 then ActiveGallery;
  558.     pgGallery:  GallerySelectedChart(Self);
  559.     pgPreviewChart:
  560.       begin
  561.         ModalResult := mrOK;
  562.         Exit;
  563.       end;
  564.   end;
  565.   RefreshButtons;
  566. end;
  567.  
  568. procedure TTeeDlgWizard.RefreshButtons;
  569. begin
  570.   PrevButton.Enabled := PageControl.ActivePage.PageIndex > 0;
  571.   With NextButton do
  572.   begin
  573.     Case PageControl.ActivePage.PageIndex of
  574.       pgTable:  Enabled:=WizardTableName<>'';
  575.       pgFields: Enabled:=LBSelectedFields.Items.Count > 0;
  576.     else
  577.       Enabled:=True;
  578.     end;
  579.     if PageControl.ActivePage.PageIndex=pgPreviewChart then
  580.        Caption := TeeMsg_ExpFinish
  581.     else
  582.        Caption := TeeMsg_ExpNext;
  583.   end;
  584. end;
  585.  
  586. Procedure TTeeDlgWizard.CreateSeries( AOwner:TComponent;
  587.                                       AChart:TCustomChart;
  588.                                       ATable:TTable;
  589.                                       ShowData:Boolean );
  590. var  t         : Integer;
  591.      tmpSeries : TChartSeries;
  592.      theField  : TField;
  593.      tmpSeriesClass: TChartSeriesClass;
  594.      NumSeries : Longint;
  595. begin
  596.   AChart.FreeAllSeries;
  597.   NumSeries:=LBSelectedFields.Items.Count;
  598.   tmpSeriesClass:= TChartSeriesClass(tmpGallery.GalleryPanel.SelectedChart[0].ClassType);
  599.   if NumSeries>1 then
  600.      if tmpSeriesClass=TPieSeries then NumSeries:=1;
  601.  
  602.   if ATable=nil then NumSeries:=1;
  603.   for t:=0 to NumSeries-1 do
  604.   begin
  605.     tmpSeries:=tmpSeriesClass.Create(AOwner);
  606.     With tmpSeries do
  607.     begin
  608.       ParentChart:=AChart;
  609.       if ATable<>nil then
  610.       begin
  611.         if AChart is TDBChart then
  612.            TDBChart(AChart).AutoRefresh:=False;
  613.         DataSource:=ATable;
  614.         MandatoryValueList.ValueSource:=LBSelectedFields.Items[t];
  615.         TheField:=ATable.FieldByName(MandatoryValueList.ValueSource);
  616.         if (t=0) and (cbLabelsFields.ItemIndex>=0) then
  617.            XLabelsSource:=cbLabelsFields.Items[cbLabelsFields.ItemIndex];
  618.         case TheField.DataType of
  619.           ftDate,
  620.           ftTime,
  621.           ftDateTime: MandatoryValueList.DateTime:=True;
  622.         else
  623.           MandatoryValueList.DateTime:=False;
  624.         end;
  625.         GetHorizAxis.Title.Caption:='';
  626.         GetVertAxis.Title.Caption:='';
  627.         if YMandatory then
  628.         begin
  629.           XValues.DateTime:=False;
  630.           if NumSeries=1 then  GetVertAxis.Title.Caption:=YValues.ValueSource;
  631.           if XLabelsSource<>'' then GetHorizAxis.Title.Caption:=XLabelsSource;
  632.         end
  633.         else
  634.         begin
  635.           YValues.DateTime:=False;
  636.           if NumSeries=1 then GetHorizAxis.Title.Caption:=XValues.ValueSource;
  637.           if XLabelsSource<>'' then GetVertAxis.Title.Caption:=XLabelsSource;
  638.         end;
  639.         Title:=MandatoryValueList.ValueSource;
  640.       end
  641.       else FillSampleValues(8);
  642.       Name:=TeeMsg_DefaultSeriesName+IntToStr(AChart.SeriesCount);
  643.       ColorEachPoint:=NumSeries=1;
  644.       Marks.Style:=smsValue;
  645.       Marks.Visible:=CBShowMarksOption.Checked;
  646.       if AChart is TDBChart then
  647.         TDBChart(AChart).AutoRefresh:=True;
  648.     end;
  649.   end;
  650.   AChart.View3D:=tmpGallery.GalleryPanel.SelectedChart.View3D;
  651.   if ATable<>nil then
  652.   begin
  653.     AChart.Title.Text.Clear;
  654.     AChart.Title.Text.Add(ATable.TableName);
  655.     if ShowData then
  656.        if AChart is TDBChart then
  657.           TDBChart(AChart).RefreshData;
  658.   end;
  659. end;
  660.  
  661. { Create the dialog defined by the user }
  662. function TTeeDlgWizard.DoFormCreation(const FormIdent: string): TForm;
  663. var
  664.   tmpChart : TCustomChart;
  665.   tmpTable : TTable;
  666. begin
  667.   Result := TForm.Create(nil);
  668.   Proxies.CreateSubClass(Result, 'T' + FormIdent, TForm);  { <-- dont translate }
  669.   with Result do
  670.   begin
  671.     Name := FormIdent;
  672.     Caption := FormIdent;
  673.     Width:=470;
  674.     Height:=300;
  675.     with Font do
  676.     begin
  677.       Name := GetDefaultFontName;
  678.       Size := GetDefaultFontSize;
  679.     end;
  680.  
  681.     if rbDatabase.Checked then
  682.     begin
  683.       tmpTable:=TTable.Create(Result);
  684.       With tmpTable do
  685.       begin
  686.         Left:=12;
  687.         Top:=8;
  688.         Name:=TeeMsg_WizardTable1;
  689.         if WizardAliasName<>'' then DatabaseName:=WizardAliasName
  690.                                else DatabaseName:=WizardPath;
  691.         TableName:=WizardTableName;
  692.         Open; {<---- Crash }
  693.       end;
  694.       tmpChart:=TDBChart.Create(Result);
  695.       With tmpChart do
  696.       begin
  697.         Parent:=Result;
  698.         Name:=TeeMsg_WizardDBChart1;
  699.         Left:=48;
  700.         Top:=8;
  701.       end;
  702.       tmpChart.Assign(PreviewChart as TCustomChart);
  703.       CreateSeries(Result,tmpChart,tmpTable,False);
  704.     end
  705.     else
  706.     begin
  707.       tmpChart:=TChart.Create(Result);
  708.       With tmpChart do
  709.       begin
  710.         Parent:=Result;
  711.         Name:=TeeMsg_WizardChart1;
  712.         Left:=48;
  713.         Top:=8;
  714.       end;
  715.       tmpChart.Assign(PreviewChart as TCustomChart);
  716.       CreateSeries(Result,tmpChart,nil,False);
  717.     end;
  718.   end;
  719. end;
  720.  
  721. procedure TTeeDlgWizard.FmtWrite(Stream: TStream; Const Fmt: String;
  722.   const Args: array of const);
  723. begin
  724.   if (Stream <> nil) and (SourceBuffer <> nil) then
  725.   begin
  726.     StrLFmt(SourceBuffer, SourceBufferSize, @Fmt[1], Args);
  727.     Stream.Write(SourceBuffer[0], StrLen(SourceBuffer));
  728.   end;
  729. end;
  730.  
  731. {$IFDEF C3}
  732. const
  733.   CRLF = #13#10;
  734.   DashLine =
  735.   '//----------------------------------------------------------------------------';
  736.  
  737. function TTeeDlgWizard.CreateHeader(const UnitIdent, FormIdent:                                         string): TMemoryStream;
  738. var t: Integer;
  739. begin
  740.   SourceBuffer := StrAlloc(SourceBufferSize);
  741.   try
  742.     Result := TMemoryStream.Create;
  743.     try
  744.       FmtWrite(Result,
  745.         DashLine + CRLF +
  746.         '#ifndef %0:sH' + CRLF +
  747.         '#define %0:sH' + CRLF +
  748.         DashLine + CRLF +
  749.         '#include <vcl\Classes.hpp>' + CRLF +
  750.         '#include <vcl\Controls.hpp>' + CRLF +
  751.         '#include <vcl\StdCtrls.hpp>' + CRLF +
  752.         '#include <vcl\Forms.hpp>' + CRLF +
  753.         '#include <vcl\TeEngine.hpp>' + CRLF +
  754.         '#include <vcl\TeeProcs.hpp>' + CRLF +
  755.         '#include <vcl\Chart.hpp>' + CRLF, [UnitIdent]);
  756.       if rbDatabase.Checked then
  757.         FmtWrite(Result,
  758.           '#include <vcl\DBChart.hpp>' + CRLF +
  759.           '#include <vcl\DB.hpp>' + CRLF +
  760.           '#include <vcl\DBTables.hpp>' + CRLF, [nil]);
  761.  
  762.       FmtWrite(Result, DashLine + CRLF, [nil]);
  763.  
  764.       FmtWrite(Result,
  765.         'class T%s : public TForm' + CRLF +
  766.         '{' + CRLF +
  767.         '__published:' + CRLF, [FormIdent]);
  768.  
  769.       if rbDatabase.Checked then
  770.       begin
  771.          FmtWrite(Result,'TTable *Table1;' + CRLF, [nil]);
  772.          FmtWrite(Result,'TDBChart *DBChart1;' + CRLF, [nil]);
  773.       end
  774.       else
  775.          FmtWrite(Result,'TChart *Chart1;' + CRLF, [nil]);
  776.  
  777.       for t:=0 to PreviewChart.SeriesCount-1 do
  778.       begin
  779.         FmtWrite(Result,
  780.            '%s *%s;'+CRLF,
  781.            [PreviewChart[t].ClassName,PreviewChart[t].Name]);
  782.       end;
  783.  
  784.       FmtWrite(Result,'private:'+CRLF +
  785.                'public:' +CRLF +
  786.                '  __fastcall T%0:s::T%0:s(TComponent* Owner);' + CRLF +
  787.                '};' + CRLF ,[FormIdent]);
  788.       FmtWrite(Result,
  789.         DashLine + CRLF +
  790.         'extern  T%0:s *%0:s;' + CRLF +
  791.         DashLine + CRLF +
  792.         '#endif', [FormIdent]);
  793.       Result.Position := 0;
  794.     except
  795.       Result.Free;
  796.       raise;
  797.     end;
  798.   finally
  799.     StrDispose(SourceBuffer);
  800.   end;
  801. end;
  802.  
  803. function TTeeDlgWizard.CreateCppSource(const FormIdent: string): TMemoryStream;
  804. begin
  805.   SourceBuffer := StrAlloc(SourceBufferSize);
  806.   try
  807.     Result := TMemoryStream.Create;
  808.     try
  809.       FmtWrite(Result,
  810.         DashLine + CRLF +
  811.         '#include <vcl\vcl.h>' + CRLF +
  812.         '#pragma hdrstop' + CRLF +
  813.         CRLF +
  814.         '#include "%0:s.h"' + CRLF +
  815.         DashLine + CRLF +
  816.         '#pragma resource "*.dfm"' + CRLF +
  817.         'T%1:s *%1:s;' + CRLF +
  818.         DashLine + CRLF +
  819.         '__fastcall T%1:s::T%1:s(TComponent* Owner)' + CRLF +
  820.         '    : TForm(Owner)' + CRLF +
  821.         '{' + CRLF +
  822.         '}' + CRLF +
  823.         DashLine, [FormIdent, FormIdent]);
  824.       Result.Position := 0;
  825.     except
  826.       Result.Free;
  827.       raise;
  828.     end;
  829.   finally
  830.     StrDispose(SourceBuffer);
  831.   end;
  832. end;
  833. {$ENDIF}
  834.  
  835. function TTeeDlgWizard.CreateSource(const UnitIdent, FormIdent: string): TMemoryStream;
  836. const  CRLF = #13#10;
  837. var  t: Integer;
  838. begin
  839.   SourceBuffer := StrAlloc(SourceBufferSize);
  840.   try
  841.     Result := TMemoryStream.Create;
  842.     try
  843.       { unit header and uses clause }
  844.       FmtWrite(Result,
  845.         'unit %s;' + CRLF + CRLF +
  846.         'interface' + CRLF + CRLF +
  847.         'uses'+CRLF +
  848.         '  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,'+CRLF+
  849.         '  StdCtrls, ExtCtrls, TeEngine, TeeProcs, Chart', [UnitIdent]);
  850.  
  851.       { additional units that may be needed }
  852.       if rbDatabase.Checked then FmtWrite(Result, ',DBChart, DB, DBTables', [nil]);
  853.  
  854.       FmtWrite(Result, ';' + CRLF + CRLF, [nil]);
  855.  
  856.       { begin the class declaration }
  857.       FmtWrite(Result,
  858.         'type'+CRLF +
  859.         '  T%s = class(TForm)'+CRLF, [FormIdent]);
  860.  
  861.       { add variable declarations }
  862.  
  863.       if rbDatabase.Checked then
  864.       begin
  865.          FmtWrite(Result,'    Table1 : TTable;' + CRLF, [nil]);
  866.          FmtWrite(Result,'    DBChart1 : TDBChart;' + CRLF, [nil]);
  867.       end
  868.       else
  869.          FmtWrite(Result,'    Chart1 : TChart;' + CRLF, [nil]);
  870.  
  871.       for t:=0 to PreviewChart.SeriesCount-1 do
  872.       begin
  873.         FmtWrite(Result,
  874.            '    %s: %s;'+CRLF,
  875.            [PreviewChart[t].Name,PreviewChart[t].ClassName]);
  876.       end;
  877.  
  878.       FmtWrite(Result,
  879.         '  private'+CRLF+
  880.         '    '+TeeMsg_PrivateDeclarations+CRLF+
  881.         '  public'+CRLF+
  882.         '    '+TeeMsg_PublicDeclarations+CRLF+
  883.         '  end;' + CRLF + CRLF +
  884.         'var' + CRLF +
  885.         '  %s: T%s;' + CRLF + CRLF +
  886.         'implementation' + CRLF + CRLF +
  887.         '{$R *.DFM}' + CRLF + CRLF, [FormIdent, FormIdent]);
  888.  
  889.       FmtWrite(Result, 'end.' + CRLF, [nil]);
  890.       Result.Position := 0;
  891.     except
  892.       Result.Free;
  893.       raise;
  894.     end;
  895.   finally
  896.     StrDispose(SourceBuffer);
  897.   end;
  898. end;
  899.  
  900. function TTeeDlgWizard.CreateForm(const FormIdent: string): TMemoryStream;
  901. var ChartForm: TForm;
  902. begin
  903.   ChartForm := DoFormCreation(FormIdent);
  904.   try
  905.     Result := TMemoryStream.Create;
  906.     Result.WriteComponentRes(FormIdent, ChartForm);
  907.     Result.Position := 0;
  908.   finally
  909.     ChartForm.Free;
  910.   end;
  911. end;
  912.  
  913. procedure TTeeDlgWizard.Button5Click(Sender: TObject);
  914. begin
  915.   MoveListAll(LBAvailFields,LBSelectedFields);
  916.   RefreshButtons;
  917. end;
  918.  
  919. procedure TTeeDlgWizard.Button4Click(Sender: TObject);
  920. begin
  921.   MoveListAll(LBSelectedFields,LBAvailFields);
  922.   RefreshButtons;
  923. end;
  924.  
  925. procedure TTeeDlgWizard.Button2Click(Sender: TObject);
  926. begin
  927.   MoveList(LBSelectedFields,LBAvailFields);
  928.   RefreshButtons;
  929. end;
  930.  
  931. procedure TTeeDlgWizard.Button3Click(Sender: TObject);
  932. begin
  933.   MoveList(LBAvailFields,LBSelectedFields);
  934.   RefreshButtons;
  935. end;
  936.  
  937. procedure TTeeDlgWizard.LBAvailFieldsClick(Sender: TObject);
  938. begin
  939.   Button3.Enabled:=LBAvailFields.SelCount>0;
  940. end;
  941.  
  942. procedure TTeeDlgWizard.LBSelectedFieldsClick(Sender: TObject);
  943. begin
  944.   Button2.Enabled:=LBSelectedFields.SelCount>0;
  945. end;
  946.  
  947. procedure TTeeDlgWizard.rbChart3DClick(Sender: TObject);
  948. begin
  949.   tmpGallery.CB3D.Checked:=True;
  950.   rbChart3D.Checked:=True;
  951.   rbChart2D.Checked:=False;
  952. end;
  953.  
  954. procedure TTeeDlgWizard.rbChart2DClick(Sender: TObject);
  955. begin
  956.   tmpGallery.CB3D.Checked:=False;
  957.   rbChart2D.Checked:=True;
  958.   rbChart3D.Checked:=False;
  959. end;
  960.  
  961. procedure TTeeDlgWizard.Image1Click(Sender: TObject);
  962. begin
  963.   TeeShowAboutBox({$IFDEF TEETRIAL}True{$ELSE}False{$ENDIF});
  964. end;
  965.  
  966. procedure TeeChartWizard(ToolServices: TIToolServices);
  967. var D             : TTeeDlgWizard;
  968.     {$IFDEF C3}
  969.     IHeaderStream : IStream;
  970.     ISourceStream : IStream;
  971.     IFormStream   : IStream;
  972.     {$ELSE}
  973.     ISourceStream : TIMemoryStream;
  974.     IFormStream   : TIMemoryStream;
  975.     {$ENDIF}
  976.     UnitIdent     : String;
  977.     FormIdent     : String;
  978.     FileName      : String;
  979. begin
  980.   if ToolServices = nil then Exit;
  981.   if ToolServices.GetNewModuleName(UnitIdent, FileName) then
  982.   begin
  983.     D := TTeeDlgWizard.Create(Application);
  984.     try
  985.       if D.ShowModal = mrOK then
  986.       begin
  987.         UnitIdent := LowerCase(UnitIdent);
  988.         UnitIdent[1] := Upcase(UnitIdent[1]);
  989.         FormIdent := 'Form' + Copy(UnitIdent, 5, 255);
  990.  
  991.         IFormStream := TIMemoryStream.Create(D.CreateForm(FormIdent));
  992.         {$IFDEF C3}
  993.           IHeaderStream := TIMemoryStream.Create(D.CreateHeader(UnitIdent,FormIdent), soOwned);
  994.           ISourceStream := TIMemoryStream.Create(D.CreateCppSource(UnitIdent,FormIdent), soOwned);
  995.           ToolServices.CreateCppModule(FileName, '', '', '', IHeaderStream,
  996.             ISourceStream, IFormStream, [cmAddToProject, cmShowSource,
  997.             cmShowForm, cmUnNamed, cmMarkModified]);
  998.         {$ELSE}
  999.           try
  1000.             {$IFNDEF D4}
  1001.             IFormStream.AddRef;
  1002.             {$ENDIF}
  1003.             ISourceStream := TIMemoryStream.Create(D.CreateSource(UnitIdent,FormIdent));
  1004.             try
  1005.               {$IFNDEF D4}
  1006.               ISourceStream.AddRef;
  1007.               {$ENDIF}
  1008.               ToolServices.CreateModule(FileName, ISourceStream, IFormStream,
  1009.                 [ cmAddToProject, cmShowSource, cmShowForm, cmUnNamed,
  1010.                   cmMarkModified]);
  1011.             finally
  1012.               {$IFNDEF D4}
  1013.               ISourceStream.OwnStream := True;
  1014.               ISourceStream.Free;
  1015.               {$ENDIF}
  1016.             end;
  1017.           finally
  1018.             {$IFNDEF D4}
  1019.             IFormStream.OwnStream := True;
  1020.             IFormStream.Free;
  1021.             {$ENDIF}
  1022.           end;
  1023.         {$ENDIF}
  1024.       end;
  1025.     finally
  1026.       D.Free;
  1027.     end;
  1028.   end;
  1029. end;
  1030.  
  1031. procedure TTeeDlgWizard.SetChartOptions;
  1032. begin
  1033.   With PreviewChart do
  1034.   begin
  1035.     CB3DOption.Checked:=View3D;
  1036.     CBShowLegendOption.Checked:=Legend.Visible;
  1037.   end;
  1038. end;
  1039.  
  1040. procedure TTeeDlgWizard.CB3DOptionClick(Sender: TObject);
  1041. begin
  1042.   PreviewChart.View3D:=CB3DOption.Checked;
  1043.   if CB3DOption.Checked then rbChart3DClick(Self)
  1044.                         else rbChart2DClick(Self);
  1045. end;
  1046.  
  1047. procedure TTeeDlgWizard.CBShowLegendOptionClick(Sender: TObject);
  1048. begin
  1049.   PreviewChart.Legend.Visible:=CBShowLegendOption.Checked;
  1050. end;
  1051.  
  1052. procedure TTeeDlgWizard.CBShowMarksOptionClick(Sender: TObject);
  1053. var t:Longint;
  1054. begin
  1055.   for t:=0 to PreviewChart.SeriesCount-1 do
  1056.      PreviewChart[t].Marks.Visible:=CBShowMarksOption.Checked;
  1057. end;
  1058.  
  1059. procedure TTeeDlgWizard.FormKeyDown(Sender: TObject; var Key: Word;
  1060.   Shift: TShiftState);
  1061. begin
  1062.   if (PageControl.ActivePage.PageIndex=pgGallery) and
  1063.      Assigned(tmpGallery) then tmpGallery.FormKeyDown(Sender,Key,Shift);
  1064. end;
  1065.  
  1066. procedure TTeeDlgWizard.FormCloseQuery(Sender: TObject;
  1067.   var CanClose: Boolean);
  1068. begin
  1069.   CanClose:=( ModalResult<>mrCancel ) or
  1070.             ( MessageDlg( TeeMsg_WizardSureToClose,
  1071.                           mtConfirmation,
  1072.                           [mbYes,mbNo],
  1073.                           0)=mrYes);
  1074. end;
  1075.  
  1076. procedure TTeeDlgWizard.Button1Click(Sender: TObject);
  1077. Const TeeHLPName='TEECHART.HLP';   { <-- don't translate }
  1078. begin
  1079. {$IFDEF D3}
  1080.   HelpFile:=TeeHLPName;
  1081. {$ELSE}
  1082.   Application.HelpFile:=TeeHLPName;
  1083. {$ENDIF}
  1084.   Application.HelpJump('TeeChart_Wizard');  { <-- don't translate }
  1085. end;
  1086.  
  1087. procedure TTeeDlgWizard.FormClose(Sender: TObject;
  1088.   var Action: TCloseAction);
  1089. begin
  1090.   {$I-}
  1091.   ChDir(BackupDir);
  1092.   if IOResult<>0 then ;
  1093. end;
  1094.  
  1095. procedure TTeeDlgWizard.LabelURLClick(Sender: TObject);
  1096. begin
  1097. {$IFNDEF D1}
  1098.   GotoURL(Handle,LabelURL.Caption);
  1099. {$ENDIF}
  1100. end;
  1101.  
  1102. end.
  1103.  
  1104.  
  1105.  
  1106.